<?php

class Model_ServicePaypercall extends Model_Service
{

	public function loginCheck($dpt_id, $dpt_account_login, $password="")
	{
		$service_info = $this->getServiceInfo($dpt_id);
			
		//$dbconn = $this->getServiceConn($dpt_id);

		//if (isset($dbconn['all']))
		if (1)
		{
			$select  = $this->db->select()->from('acc_client');
			$select->where('email = ?', $dpt_account_login);
				
			$user = $this->db->fetchRow($select);
			//Zend_Debug::dump($user);
			$passwd = md5($password);
				
			if (!$user)
			{
				$rs['status'] = false;
				$rs['message'] = 'account not found';
			}
			else
			{
				$status = $user['status'];
				$passwd_stored = $user['password'];
				 
				if ($status =='Disable')
				{
					$rs['status'] = false;
					$rs['message'] = 'account not active';
				}
				elseif ($password && $passwd !=$passwd_stored)
				{
					$rs['status'] = false;
					$rs['message'] = 'wrong password';
				}
				else
				{
					$rs['status'] = true;
					$rs['dpt_account_id'] = $user['client_id'];
					$rs['dpt_account_login'] = $dpt_account_login;
					$rs['role'] = $user['role'];
					$rs['email'] = $dpt_account_login;
					 
					$rs['login_area'] = 'member';

				}
			}
		}
		else
		{
			$rs['status'] = false;
			$rs['message'] = 'service connection error';
		}

		return $rs; // return OK if passed
	}


	public static function addRemoteUser($client_id)
	{
		$model_service = new Model_Service();
		$service_info = $model_service->getServiceInfo(3009);  //dpt_id=3009
		
		$client_service=$model_service->getClientDptService(3009, $client_id);
		if (empty($client_service)){		
			$rpc_url = $service_info['api_url'];
			$client = new Zend_XmlRpc_Client($rpc_url);
			$user_id = $client->getProxy()->addUser($client_id); //$dpt_account_id:client_id
			return $user_id;		
		}else{
			return 0;
		}
	}

	public static function disableRemoteUser($user_id)
	{
		$model_service = new Model_Service();
		$service_info = $model_service->getServiceInfo(3009);  //dpt_id=3009
		$rpc_url = $service_info['api_url'];
		$client = new Zend_XmlRpc_Client($rpc_url);
		return $client->getProxy()->disableUser($user_id);
	}
}